<template>
	<view>
		<!-- <free-nav-bar title="通知公告" showBack></free-nav-bar> -->
		<scroll-view scroll-y scroll-with-animation style="height: calc(100vh - 50px)" :show-scrollbar="false"
			@scrolltolower="loadMore" @scrolltoupper="refresh">
			<view class="mt-1 pl-3 dfex pr-3 lineHight-3 border-f5f5f5" v-for="(notice, index) in notices" :key="index"
				@click="getDiClick(notice.id)">
				<view class="dfes">
					<view v-if="!notice.isRead" @click="readNotice(notice)"
						style="color: #ff0000; padding-right: 5px">●</view>
					<view class="wrap" @click="readNotice(notice)"
						:style="{ color: !notice.isRead ? '#333' : '#999999' }">{{ notice.title }}</view>
				</view>
			<view class="text-999999 font-14" style="width: 100px; text-align: right;">{{notice.updateTime.slice(0, 10)}}</view>
			</view>
			
			
			<view v-if="!hasMore && notices.length > 0" class="text-center mt-3 mb-3">
				<view class="text-muted">没有更多数据了</view>
			</view>
			<view v-else-if="!hasMore && notices.length === 0" class="text-center mt-3 mb-3">
				<view class="text-muted">暂无数据</view>
			</view>
			<view v-else class="text-center mt-3 mb-3">
				<view class="btn btn-primary">加载更多</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import freeNavBar from '@/components/free-ui/free-nav-bar.vue'
	import $H from '@/common/free-lib/request.js'
	export default {
		components: {
			freeNavBar,
		},
		data() {
			return {
				notices: [],
				form: {
					pageNo: 1,
					pageSize: 10,
					total: 0 // 总页数
				},
				hasMore: true, // 是否还有更多数据
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			readNotice(notice) {
				// 点击浏览后将未读状态设置为已读
				$H.get(
					`/basisInform/platformNotice/down/clickRead`, {
						id: notice.id
					}, {
						token: true
					}
				)
			},
			getDiClick(id) {
				uni.navigateTo({
					url: `/pages/tabbar/index/NewListDi?id=${id}`
				})
			},
			getList() {
				$H.get(
					`/basisInform/platformNotice/down/list`,
					{...this.form}, {token: true}
				).then((res) => {
					this.notices = res.result.records,
					this.form.total = res.result.total;
					this.hasMore = this.notices.length < this.form.total;
				})
			},
			// 加载更多
			loadMore() {
			
				if (this.form.pageNo * this.form.pageSize >= this.form.total) {
					this.hasMore = false;
					return;
				}
				this.form.pageNo++;
				// 请求数据
				this.getList();
			},
			// 下拉刷新
			refresh() {
				// 重置页码为 1
				this.form.pageNo = 1;
				// 清空数据列表
				this.notices = [];
				// 设置标记为有更多数据
				this.hasMore = true;
				// 重新请求数据
				this.getList();
				// 结束下拉刷新动画
				uni.$emit('stopPullDownRefresh');
			},
		},
	}
</script>
<style></style>